<template>
  <!-- 访客信息（拥有进入资格的员工进入数与登记访客进入数） -->
  <div class="visitor-info chart-box1">
    <div class="chart-title">人流占比</div>
    <div class="chart-content">
      <a-row :gutter="12" align="middle" style="height: 30%">
        <a-col :span="8" class="text-right chart-container">
          <div style="color: #1699b7; height: 50%">
            <span>男性：</span>
            <span class="number" style="font-size: 2.4rem">
              <count-to
                :start-val="sex.man.oldVal"
                :end-val="sex.man.newVal"
                :duration="3000"
              />
              %
            </span>
          </div>
          <div style="width: 100%; height: 50%">
            <Decoration8 :color="['#1699b7', 'transparent']" />
          </div>
        </a-col>
        <a-col :span="4">
          <cu-icon type="org-nanxing" style="font-size: 5rem; color: #fff" />
        </a-col>
        <a-col :span="4">
          <cu-icon type="org-nvxing" style="font-size: 5rem; color: #fff" />
        </a-col>
        <a-col :span="8" class="chart-container">
          <div style="color: #dc6a1f; height: 50%">
            <span>女性：</span>
            <span class="number" style="font-size: 2.4rem">
              <count-to
                :start-val="sex.woman.oldVal"
                :end-val="sex.woman.newVal"
                :duration="3000"
              />
              %
            </span>
          </div>
          <div style="width: 100%; height: 50%">
            <Decoration8 :reverse="true" :color="['#dc6a1f', 'transparent']" />
          </div>
        </a-col>
      </a-row>
      <ScrollRankingBoard
        style="height: 68%; width: 100%; margin-top: 1%"
        :config="config"
        :key="chartKey"
      ></ScrollRankingBoard>
    </div>
  </div>
</template>

<script>
import { defineComponent, reactive, toRefs, onMounted, watch } from "vue";
import { ScrollRankingBoard, Decoration8 } from "@kjgl77/datav-vue3";
import CountTo from "../countTo/index.vue";
import store from "../../../../store";
import common from "../../utils/common";

export default defineComponent({
  name: "VisitorInfo",
  components: { ScrollRankingBoard, Decoration8, CountTo },
  setup(props) {
    let keyCount = 1;
    const state = reactive({
      chartKey: `visitor_info_${keyCount}`,
      config: {
        data: [
          { name: "员工（0%）", value: 0 },
          { name: "访客（0%）", value: 0 },
        ],
        rowNum: 2,
      },
      sex: {
        man: { ...common.countToInit },
        woman: { ...common.countToInit },
      },
    });
    watch(
      () => store.getters.resizeTrigger,
      () => {
        keyCount++;
        state.chartKey = `visitor_info_${keyCount}`;
      }
    );

    watch(
      () => store.getters.flow.PeopleStreamScale,
      (val) => {
        if (val) {
          getData();
        }
      }
    );

    const getData = () => {
      const { PeopleStreamScale } = store.getters.flow;
      if (PeopleStreamScale) {
        state.config.data = [
          {
            name: `员工（${PeopleStreamScale.staff.percent}%）`,
            value: PeopleStreamScale.staff.value,
          },
          {
            name: `访客（${PeopleStreamScale.visitor.percent}%）`,
            value: PeopleStreamScale.visitor.value,
          },
        ];
        state.sex.man.oldVal = state.sex.man.newVal;
        state.sex.man.newVal = Number(PeopleStreamScale.man.percent);
        state.sex.woman.oldVal = state.sex.woman.newVal;
        state.sex.woman.newVal = Number(PeopleStreamScale.woman.percent);
      }
    };

    getData();

    return {
      ...toRefs(state),
    };
  },
});
</script>

<style lang="less" scoped>
@import "../../styles/common.less";
</style>
